
let reg1 = /^[\u4E00-\u9FA5]{2,10}$/;
let reg2 = /^[a-zA-Z0-9_-]{3,16}$/;


function my() {
    let login = getCookie('login');
    let loginbody = document.querySelector('.loginbody');
    if (!login) {
        loginbody.innerHTML = `
    
    <div class="nologin">
    <h5>请先登录</h5>
    <p>
        <label for="">用户名:</label>
        <input type="username"  id="username" >
    </p>
    <p>
        <label for="">&nbsp;&nbsp;&nbsp;密码:</label>
        <input type="password" id="password">
    </p>
    <button class='mylogin'>登录</button>
    </div>
    
    `;
        // return;
$('.mylogin').click(function () {
    let username = document.querySelector('#username');
    let password = document.querySelector('#password');
    if (reg1.test(username.value) && reg2.test(password.value)) {
        pAjax({
            url:'../php/login.php',
            type: 'post',
            data: {
                username: username.value,
                password:password.value,
            }
        }).then(res => {
            res = JSON.parse(res);
            if (res.code) {
                setCookie('login', username.value);
                my();
            }
        });
    }
});

    
    } else {
        loginbody.innerHTML = `
        <div class="logining">
        <div class="top">
        <a href="">
        <p>
            <b>我的订单</b>
            <i>></i>
        </p>
        </a>
        <a href="">
        <p>
            <b>优惠券</b>
            <i>></i>
        </p>
        </a>
        <a href="">
        <p>
            <b>影院会员卡</b>
            <i>></i>
        </p>
        </a>
        </div>
            <div class="top">
            <a href="">
        <p>
            <b>想看的电影</b>
            <i>></i>
        </p>
    </a>
        <a href="">
        <p>
            <b>看过的电影</b>
            <i>></i>
        </p>
    </a>

        </div>
        <em class="exitlogin">退出登录</em>
    </div> 
        `;
    }
$('.exitlogin').click(function () {
    setCookie('login', '111', -1);
    my();
})
}

my();



